package com.ruoyi.web.controller.gasoline;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.MainGasoline;
import com.ruoyi.service.IMainGasolineService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-06-23
 */
@Controller
@RequestMapping("/ruoyi/oilcard")
public class MainCardContraller extends BaseController
{
    private String prefix = "ruoyi/Maingasoline";

    @Autowired
    private IMainGasolineService mainGasolineService;

    @RequiresPermissions("ruoyi:oilcard:view")
    @GetMapping()
    public String gasoline( ModelMap map,MainGasoline mainGasoline1)
    {
        List<MainGasoline> list = mainGasolineService.selectMainGasolineList(mainGasoline1);
        MainGasoline mainGasoline=new MainGasoline();

//        for(MainGasoline MainGasoline:list){
//            bigDecimal.add(MainGasoline.getmTopup());
//
//        }
        BigDecimal bigDecimal=BigDecimal.valueOf(0.0D);
        for (MainGasoline gasoline : list) {
            bigDecimal=bigDecimal.add(gasoline.getmTopup());
            mainGasoline.setmTopup(bigDecimal);
        }
        for(int s=0;s<=list.size();s++){
            if(s==list.size()-1){
                mainGasoline.setmMoney(list.get(s).getmMoney());
            }
        }
        map.put("mainGasoline", mainGasoline);
        return prefix + "/oilcard";
    }


    /**
     * 主油卡费用明细
     */
    @RequiresPermissions("ruoyi:oilcard:list")
    @PostMapping("/lists")
    @ResponseBody
    public TableDataInfo listmain(MainGasoline mainGasoline)
    {
        startPage();
        List<MainGasoline> list = mainGasolineService.selectMainGasolineList(mainGasoline);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("ruoyi:oilcard:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MainGasoline mainGasoline)
    {
        List<MainGasoline> list = mainGasolineService.selectMainGasolineList(mainGasoline);
        ExcelUtil<MainGasoline> util = new ExcelUtil<MainGasoline>(MainGasoline.class);
        return util.exportExcel(list, "Maingasoline");
    }

}
